package com.xdl.flytest.util;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Auther: 80736
 * @Date: 2018/12/24 16:00
 * @Description: 全局异常处理器
 */
public class GlobalHandlerExceptionResolver implements HandlerExceptionResolver {


    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {

        TestCaseException exception;
        if (ex instanceof TestCaseException) {
            exception = (TestCaseException) ex;
        } else {
            exception = new TestCaseException("Testcase未知错误");
        }
        ModelAndView mav = new ModelAndView("page-error");
        mav.addObject("message", exception.getMessage());

        return mav;
    }
}
